<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
    es5 Object.defineProperty
    */
   var obj = {
     a: 10,
     b: 20
   }
   var b = 20;
   Object.defineProperty(obj, 'b', {
     /* 
      新增了两个拦截器 
        对于 这个属性 取值拦截   getter  
                    赋值拦截    setter
     */
      get(){
        console.log('getter触发');
        return b;
      },
      set(val){
        console.log('setter触发', val);
        b = val;
      }
   })

   console.log(obj.b);
   obj.b = 200;
   console.log(obj.b);
  </script>
</body>
</html>